<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
        body, html{width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
        #allmap {height:500px; width: 100%;}
        #control{width:100%;}
    </style>
    <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=kNVRaXn72gV5WCM735g3uwz5anrQAfGY"></script>
    <title>13213</title>
</head>
<body>
<div id="allmap"></div>
<div id="control">
    <button onclick = "polyline.enableEditing();polygon.enableEditing();">开启线、面编辑功能</button>
    <button onclick = "polyline.disableEditing();polygon.disableEditing();">关闭线、面编辑功能</button>
</div>
</body>
</html>
<script>
    //根据经纬极值计算绽放级别。
    function getZoom (maxLng, minLng, maxLat, minLat) {
        var zoom = ["50","100","200","500","1000","2000","5000","10000","20000","25000","50000","100000","200000","500000","1000000","2000000"]//级别18到3。
        var pointA = new BMap.Point(maxLng,maxLat);  // 创建点坐标A
        var pointB = new BMap.Point(minLng,minLat);  // 创建点坐标B
        var distance = map.getDistance(pointA,pointB).toFixed(1);  //获取两点距离,保留小数点后两位
        for (var i = 0,zoomLen = zoom.length; i < zoomLen; i++) {
            if(zoom[i] - distance > 0){
                return 18-i+3;//之所以会多3，是因为地图范围常常是比例尺距离的10倍以上。所以级别会增加3。
            }
        }
    }

</script>
<script type="text/javascript">
    // 百度地图API功能
    var map = new BMap.Map("allmap");
    map.centerAndZoom(new BMap.Point(116.404, 39.915), 15);
    map.enableScrollWheelZoom();

    var polyline = new BMap.Polyline([
        new BMap.Point(116.399, 39.910),
        new BMap.Point(116.405, 39.920),
        new BMap.Point(116.423493, 39.907445)
    ], {strokeColor:"blue", strokeWeight:2, strokeOpacity:0.5});   //创建折线
    map.addOverlay(polyline);   //增加折线

    var polygon = new BMap.Polygon([
        new BMap.Point(116.387112,39.920977),
        new BMap.Point(116.385243,39.913063),
        new BMap.Point(116.394226,39.917988),
        new BMap.Point(116.401772,39.921364),
        new BMap.Point(116.41248,39.927893)
    ], {strokeColor:"blue", strokeWeight:2, strokeOpacity:0.5});  //创建多边形
    map.addOverlay(polygon);   //增加多边形
</script>

